const dbhelp = require('../../util/Dbhelp')

const dbshopcar = async (obj)=>{
    let data = await dbhelp.sql(`select * from ShopCar join Goods on Goods.goodsID = ShopCar.goodsID where ShopCar.userID=${obj.userID}`)
    return {
        code: 200,
        data:data.recordset
    }
}

const dbDelShop = async (obj)=>{
    let data = await dbhelp.sql(`delete from ShopCar where shopID =${obj.shopID}`)
    if(data.rowsAffected){
        return {
            code: 200,
            msg: "删除成功"
        }
    }else{
        return {
            code: 404,
            msg: "删除错误"
        }
    }
}
const dbAdd = async (obj)=>{
    let data = await dbhelp.sql(`insert into ShopCar values(${obj.userID},${obj.goodsID})`)
    if(data.rowsAffected){
        return {
            code: 200,
            msg: "添加成功"
        }
    }else{
        return {
            code: 404,
            msg: "添加错误"
        }
    }
}
module.exports = {
    dbshopcar,
    dbDelShop,
    dbAdd
}